/*------------------------------------------------------------
   ZeroMail-Ajax.js
--------------------------------------------------------------*/

//フォーカスさせる要素のID
var firstFocus = '';

//フォームのID
var form = "contactform";

//結果を表示する要素のID
var result = "result";

//リセットボタンのID
var myreset = "myreset";

//閉じるボタンの文字
var buttonText = "閉じる";

/*--------------------------------------------------------------*/

MooTools.lang.setLanguage("ja-JP");

window.addEvent("domready",function() {
		
	if(firstFocus) $(firstFocus).focus();
	$(form).addEvent("submit",function(){return false});
	
	var myValidator = new Form.Validator.Inline($(form),{errorPrefix: ""});
	
	var req = new Form.Request.Append($(form),$(result),
					 {
						resetForm:false,
						extraData :{"noscript":"false"},
						requestOptions: {
							'spinnerTarget':$(form)
						},
						revealOptions:{
							onHide:function(){
								this.element.destroy();
							}
						},
						onSuccess:function(el,html){
							req.disable();
							if(!el.get("text").test("エラー")) $(form).reset();
							new Element("button",{"id":"close","html":buttonText,"events":{"click":function(){el.dissolve();req.enable(); } }}).inject(new Element("p",{"class":"button"})).inject(el,"bottom");
							
						}
					});
	
	$(myreset).addEvent("click",function(){
        $(form).reset();
        $(form).getElements("[input|textarea]").removeClass("validation-failed");
        myValidator.reset();
    });

});